<!DOCTYPE html>
<html>
<include file="Public:header" />
<link href="__ACSS__/dialog.css" rel="stylesheet">
<link href="__ACSS__/plugins/validform/validform.css" rel="stylesheet">
<style>
	.form-control{ padding-left:5px;}
	.upload-warp{ position:relative;}
	.upload-btn{ position:absolute; top:0; right:0; border-radius:0;}

	.file-preview {border:1px solid #ddd; padding:5px; width:100%; margin-bottom:5px;}
	.file-preview-frame{ margin:8px; border:1px solid #ddd; box-shadow:1px 1px 5px 0px #a2958a; padding:6px; float:left; text-align:center; vertical-align:middle;}
	.file-preview-frame .btn{ float:right; margin-top:5px;}
	.file-preview-text{ color:#428bca; font-size:11px; text-align:center;}
	#mapContainer{width:100%; height:400px;}
	.clockpicker{ width:46%; float:left;}
	.clockpicker-addon{ width:8%; height:34px; line-height:34px; text-align:center; float:left;}
	.purchase-box{ width:90%;}
	.purchase-box span{ border:1px solid #ddd; padding:3px 10px; border-radius:4px; float:left; background:#fff; font-size:15px; position:relative; cursor:pointer; margin:0 10px 10px 0;}
	.purchase-box span i{ margin-left:8px; color:#888;}
	.purchase-box span:hover{ border:1px solid #999; background:#eee;}
</style>
  <body>
	  <div class="wrapper wrapper-content animated fadeInRight">
		<form role="form" class="form" action="__URL__/update">
			<input type="hidden" name="id" value="<{$vo.id}>">
			<input type="hidden" name="update_time" value="<php>echo time();</php>">
			<input type="hidden" name="old_username" value="<{$vo.username}>">
			<div class="form-group">
				<label class="col-sm-2 control-label">店铺名称：</label>
				<div class="col-sm-10">
					<input type="text" datatype="*" name="name" class="form-control" value="<{$vo.name}>" placeholder="店铺名称" ajaxurl="__URL__/exCheckName?id=<{$vo.id}>">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">所在学校：</label>
				<div class="col-sm-10">
					<select id="school_name" datatype="*" name="school_name" class="form-control">
						<foreach name="schoolList" item="school">
							<option value="<{$school.name}>" <if condition="$school.name eq $vo['school_name']"> selected</if>><{$school.name}></option>
						</foreach>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">所在区域：</label>
				<div class="col-sm-10">
					<select id="school_area_id" datatype="*" name="school_area_id" class="form-control">
						<foreach name="school_area" item="school_area">
							<option value="<{$school_area.id}>" <if condition="$school_area.id eq $vo['school_area_id']"> selected</if>><{$school_area.area_name}></option>
						</foreach>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">所在大楼：</label>
				<div class="col-sm-10">
					<select id="floor_num" datatype="*" name="floor_num" class="form-control">
						<foreach name="school_floor" item="school_floor">
							<option value="<{$school_floor.floor_num}>" <if condition="$school_floor.floor_num eq $vo['floor_num']"> selected</if>><{$school_floor.floor_num}></option>
						</foreach>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">最低消费：</label>
				<div class="col-sm-10">
					<input type="text" datatype="*"name="min_consumption" class="form-control" value="<{$vo.min_consumption}>" placeholder="最低消费 例如：7 或者8.5等" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否超级店：</label>
				<div class="col-sm-10">
					<label><input name="is_super" type="radio" value="0" <if condition="$vo['is_super'] eq 0"> checked="checked" </if> />普通店</label>
					<label><input name="is_super" type="radio" value="1" <if condition="$vo['is_super'] eq 1"> checked="checked" </if> />超级店</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">店主账号：</label>
				<div class="col-sm-10">
					<input type="text" datatype="*"name="username" class="form-control" value="<{$vo.username}>"  placeholder="店主账号" ajaxurl="__URL__/checkUser?old_username=<{$vo.username}>">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">超市Logo：</label>
				<div class="col-sm-10">
					<div class="file-preview">
						<div class="file-preview-thumbnails" data-num="1">
							<div class="file-preview-frame">
								<span class="file-preview-image"><img style="width:150px;" src="__IMGROOT__<{$vo.logo}>" rel="<{$vo.logo}>" ref="<{$vo.logo}>" class="file-preview-image"></span>
								<div class="clearfix"></div><button onclick="delPhoto(this)" type="button" class="btn btn-xs btn-white"><i class="glyphicon glyphicon-trash text-danger"></i></button>
							</div>
						</div>
						<div class="clearfix"></div>
					</div>
					<div class="upload-warp">
						<input class="form-control localname" type="text" placeholder="尺寸为750px*750px 50kb左右"  value="<{$vo.logo}>" nullmsg="请上传图片" errormsg="请上传图片" readonly="readonly">
						<button type="button" onclick="uploadPhoto(this)" class="btn btn-primary upload-btn"><i class="glyphicon glyphicon-folder-open"></i>&nbsp;&nbsp;选择&nbsp;...</button>
						<input type="hidden" name="logo" value="<{$vo.logo}>" class="head_picture"/>
					</div>
				</div>
			</div>
			<div class="clearfix"></div>
			<br/>
			<div class="form-group">
				<label class="col-sm-2 control-label">营业状态：</label>
				<div class="col-sm-10">
					<label><input name="status" type="radio" value="0" <if condition="$vo['status'] eq 0"> checked="checked" </if> />休息</label>
					<label><input name="status" type="radio" value="1" <if condition="$vo['status'] eq 1"> checked="checked" </if>/>营业</label>
				</div>
			</div>
			<div class="clearfix">
				<button type="submit" id="submit" class="btn btn-success btn-block">提交</button>
				<button type="reset" id="reset2" class="hidden btn btn-success btn-block">重置</button>
			</div>
		</form>
	  </div>
  </body>
<!-- 全局js -->
<include file="Public:foot" />
<script src="__AJSPLUGINS__/validform/Validform_v5.3.2_min.js"></script>
<script src="__AJS__/jquery.md5.js"></script>

<!-- Uploader -->
<script type="text/javascript" src="__AJS__/jquery.upload.js"></script>
<script>
	$(function(){
		$("#reset2").click();
		var index = parent.layer.getFrameIndex(window.name);
		var form = $(".form").Validform({
			tiptype:4,
			ajaxPost:true,
			callback:function(data){
				if(data.status == 1) {
					window.parent.layer.msg(data.info);
					window.parent.$('#table_list').trigger("reloadGrid");
				}else{
					window.parent.layer.msg(data.info);
				}
				parent.layer.close(index);
			}
		});
		$("#school_name").change(function(){
			var index = layer.load();
			$.ajax({
				url:"__URL__/schoolAreaList",
				type:"post",
				data:{'school_name':$("#school_name").val()},
				success:function(json){
					var data = eval("("+json+")").data;
					var school_area = "";
					if(data != null){
						for(var i=0; i<data.length; i++){
							school_area += '<option value="'+ data[i].id +'" ref="'+ data[i].id +'">'+ data[i].area_name +'</option>'
						}
					}else{
						school_area += '<option value="" ref="选择区域">选择区域</option>'
					}
					$("#school_area_id").html(school_area);
					layer.close(index);
				}
			});
			$.ajax({
				url:"__URL__/schoolFloorList",
				type:"post",
				data:{'school_name':$("#school_name").val()},
				success:function(json){
					var data = eval("("+json+")").data;
					var floor_num = "";
					if(data != null){
						for(var i=0; i<data.length; i++){
							floor_num += '<option value="'+ data[i].floor_num +'" ref="'+ data[i].floor_num +'">'+ data[i].floor_num +'</option>'
						}
					}
					$("#floor_num").html(floor_num);
					layer.close(index);
				}
			})
		})


	})
	//上传图
	function uploadPhoto(t){
		var arr = new Object();
		arr['t'] = t;
		arr['maxWidth'] = '750';
		arr['maxHeight'] = '750';
		arr['folderName'] = 'Shop';
		arr['prefix'] = 'm_';
		doUpload(arr);
	}
	//上传产品详细图
	function uploadDetailPhoto(t){
		var arr = new Object();
		arr['t'] = t;
		arr['maxWidth'] = '750';
		arr['folderName'] = 'Shop';
		arr['prefix'] = 'm_';
		doUpload(arr);
	}

	//上传图片
	function doUpload(arr) {
		$.upload({
			url: '__URL__/uploadImg',
			fileName: 'filedata',
			dataType: 'json',
			acceptType:'image/jpeg,image/png',
			params:{maxWidth:arr['maxWidth'],maxHeight:arr['maxHeight'],folderName:arr['folderName'],prefix:arr['prefix']},
			onSend: function() {
				return true;
			},
			// 上传之后回调
			onComplate: function(data) {
				if(data.status == 1){
					var url = data.data.url;
					var localname = data.data.localname;
					if($(arr['t']).parents(".form-group").find(".file-preview-thumbnails").attr("data-num") == 1) {
						$(arr['t']).parents(".form-group").find(".file-preview-thumbnails").html('<div class="file-preview-frame"><span class="file-preview-image"><img style="width:150px;" class="file-preview-image" ref="'+ localname  +'" rel="'+ url  +'" src=__IMGROOT__'+ url +'></span><div class="clearfix"></div><button class="btn btn-xs btn-white" type="button" onclick="delPhoto(this)"><i class="glyphicon glyphicon-trash text-danger"></i></button></div>');
					}else if($(arr['t']).parents(".form-group").find(".file-preview-thumbnails").attr("data-num") > 1) {
						$(arr['t']).parents(".form-group").find(".file-preview-thumbnails").append('<div class="file-preview-frame"><span class="file-preview-image"><img style="width:150px;" class="file-preview-image" ref="'+ localname  +'" rel="'+ url  +'" src=__IMGROOT__'+ url +'></span><div class="clearfix"></div><button class="btn btn-xs btn-white" type="button" onclick="delPhoto(this)"><i class="glyphicon glyphicon-trash text-danger"></i></button></div>');
					}
					initPhoto();
				}else{
					layer.alert(data.info);
				}
			}
		});
	}

	//删除图片
	function delPhoto(t) {
		layer.confirm('确定执行？', function(index){
			$(t).parents(".file-preview-frame").remove();
			initPhoto();
			layer.close(index);
		});
	}

	function initPhoto() {
		//上传张数上限操作
		$(".file-preview-thumbnails").each(function() {
			if($(this).attr("data-num") <= $(this).find(".file-preview-frame").length) {
				$(this).parents(".form-group").find(".upload-btn").attr("disabled","disabled");
			}else{
				$(this).parents(".form-group").find(".upload-btn").removeAttr("disabled");
			}
			if($(this).find(".file-preview-frame").length == 0) {
				$(this).parents(".file-preview").hide();
			}else{
				$(this).parents(".file-preview").show();
			}
		})
		//初始化图片相应表单属性
		$(".file-preview-thumbnails").each(function() {
			var localname = "";
			var url = "";
			$(this).find("img").each(function(index) {
				if(index == 0) {
					url += $(this).attr("rel");
					localname += $(this).attr("ref");
				}else{
					url += "|" + $(this).attr("rel");
					localname += "|" + $(this).attr("ref");
				}
			})
			$(this).parents(".form-group").find(".localname").val(localname);
			$(this).parents(".form-group").find(".head_picture").val(url);
		})
	}
</script>
</html>